package cn.edu.scau.cmi.linhuanrui.abstractFactory.controller;

import javafx.fxml.FXML;
import cn.edu.scau.cmi.linhuanrui.abstractFactory.factory.*;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.event.ActionEvent;
import javafx.scene.control.TextArea;

public class AbstractFactoryController {
	@FXML
	private TextField input1;
	@FXML
	private TextField input2;
	@FXML
	private TextArea showText;
	@FXML
	private Button ok;

	// Event Listener on TextField[#input2].onAction
	@FXML
	public void Event_Enter(ActionEvent event) {
		if(input1.getText().length()<=0) {
			input1.requestFocus();
			return;
		}
		if(input2.getText().length()<=0) {
			input2.requestFocus();
			return ;
		}
		if(event.getSource()==input1) {
			input2.requestFocus();
			return;
		}
		String company = input1.getText();
		AbstractFactory abstractFactory = null;
		switch (company) {
		case "Wens":
			abstractFactory = new WensFactory();
			break;
		case "Tianbang":
			abstractFactory = new TianbangFactory();
			break;
		case "Aonong":
			abstractFactory = new AonongFactory();
			break;
		default:
			showText.appendText("Sorry, your input is not correct!\n");
			break;
		}

		String meatType = input2.getText();
		Meat meat = null;
		switch (meatType) {
		case "Pork":
			meat = abstractFactory.creatPork();
			break;
		case "Beef":
			meat = abstractFactory.creatBeef();
			break;
		case "Chicken":
			meat = abstractFactory.creatChicken();
			break;
		default:
			showText.appendText("Sorry, your input is not correct!\n");
			break;
		}
		if (meat != null) {
			showText.appendText(meat.cook()+"\n");
		}
	}

}
